import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

def modify_trace_pps_file(filename):
    df_data = pd.read_csv(filename, header = None)
    pre_time = 0
    gap_list = []
    for index, row in df_data.iterrows():
        if row[0] < 0:
            time_seq = - row[0]
        else:
            time_seq = row[0]
        gap = time_seq - pre_time

        if gap > 200:
            gap = 200

        if row[0] < 0:
            gap_list.append(-gap)
        else:
            gap_list.append(gap)
        pre_time = time_seq

    start_time = 0
    with open('downlink-new.pps', 'w') as f:
        for gap in gap_list:
            if gap < 0:
                start_time -= gap
                f.write(str(-start_time) + '\n')
            else:
                start_time += gap
                f.write(str(start_time) + '\n')
            

if __name__ == '__main__':
    modify_trace_pps_file('downlink-1686214831.pps')
